package reflect;

import java.lang.reflect.Field;

public class ReflectDemo8 {
    public static void main(String[] args) throws Exception {
        Teacher teacher=new Teacher();
        teacher.name="张三";
        System.out.println(teacher.name);

        Class cls=Class.forName("reflect.Teacher");
        Object obj=cls.newInstance();
        System.out.println(obj);
        Field field=cls.getField("name");
        field.set(obj,"唐俊");
        System.out.println(field.get(obj));

        Field field1=cls.getDeclaredField("age");
        field1.setAccessible(true);
        field1.set(obj,18);
        System.out.println(field1.get(obj));
        field1.setAccessible(false);
    }
}
